package java_0581_thread;

public class Thread02 {
    public static void main(String[] args) {
//        Dog dog = new Dog();
//        //dog.start()不能调用start
//        //创建Thread对象，把Dog对象（实现Runnable）放入Thread
//        Thread thread = new Thread(dog);
//        thread.start();

        Tiger tiger = new Tiger();
        ThreadProxy threadProxy = new ThreadProxy(tiger);
        threadProxy.start();
    }
}
class Animal {}
class Tiger extends Animal implements Runnable{

    @Override
    public void run() {
        System.out.println("老虎叫");
    }
}


//静态代理模式
class ThreadProxy implements Runnable{//ThreadProxy线程代理
    private Runnable target = null;
    @Override
    public void run() {
        if (target!=null){
            target.run();//动态绑定
        }
    }

    public ThreadProxy(Runnable target) {
        this.target = target;
    }
    public void start(){
        start0();
    }
    public void start0(){
        run();
    }
}

class Dog implements Runnable {
    int count = 0;

    @Override
    public void run() {
        while (true) {
            System.out.println("hi" + (++count) + Thread.currentThread().getName());
            try {
                Thread.sleep(1000);
            } catch (InterruptedException e) {
                throw new RuntimeException(e);
            }
            if (count == 10) {
                break;
            }
        }
    }
}